import { Message } from 'view-design'
import store from '@/store'

const pending = (key: string, status: boolean) => {
    if (!key) return
    store.commit('pending', { key, status })
}

export const proxyActions = async (block: Function, key: string) => {
    try {
        pending(key, true)
        const result = await block()
        return result === undefined ? true : result
    } catch (error) {
        Message.error(error.message)
        return false
    } finally {
        pending(key, false)
    }
}